
package com.dog.basics.service.wishwash.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.security.util.SecurityUtils;
import com.dog.basics.bean.dto.admin.wishwash.AdminDogHxBankAddDto;
import com.dog.basics.bean.vo.admin.wishwash.AdminDogHxBankInfoVo;

import java.util.List;
import java.util.stream.Collectors;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dog.basics.bean.model.wishwash.DogHxBank;
import com.dog.basics.dao.wishwash.DogHxBankMapper;
import com.dog.basics.service.wishwash.DogHxBankService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 银行卡信息
 *
 * @author cy code generator
 * @date 2021-07-09 17:40:27
 */
@Service
@AllArgsConstructor
public class DogHxBankServiceImpl extends ServiceImpl<DogHxBankMapper, DogHxBank> implements DogHxBankService {


    /**
     * @Description: 后台管理查询本人银行卡
     * @Param: obj
     * @return: Boolean
     * @author cy code generator
     * @date 2021-07-09 17:40:27
     */
    @Override
    public AdminDogHxBankInfoVo getAdminObjXq() {
        // 后台管理 - 查询数据信息是否存在
        DogHxBank obj = this.getById(SecurityUtils.getSysUser().getUserId());
        // 判断数据是否存在
        if (ObjectUtil.isNull(obj)){
            return null;
        }
        // 数据信息格式化 - 返回
        AdminDogHxBankInfoVo objVo = BeanUtil.toBean(obj, AdminDogHxBankInfoVo.class);
        return objVo;
    }

    /**
     * @Description: 后台管理增加[增加|修改]
     * @Param: obj
     * @return: Boolean
     * @author cy code generator
     * @date 2021-07-09 17:40:27
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveAdminObj(AdminDogHxBankAddDto obj) {
        // 后台管理 - 数据信息转换
        DogHxBank objAdd = BeanUtil.toBean(obj, DogHxBank.class);
        // 数据信息补充
        objAdd.setId(SecurityUtils.getSysUser().getUserId());
        objAdd.setCreateTime(DateUtil.currentSeconds());
        objAdd.setCreateBy(SecurityUtils.getSysUser().getUserId());
        // 执行添加数据信息
        Validator.validateTrue(this.saveOrUpdate(objAdd), "保存失败!");
        return Boolean.TRUE;
    }


}
